home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # gateways-config.cgi
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: gateways-config.frm,v 1.36 1997/06/24 22:20:51 shotes Exp $
-
- require "/usr/OnRamp/lib/OnRamp.pm";
- require "/usr/OnRamp/lib/java.pm";
-
- $conf = "/etc/gateways";
- $dummy = "/etc/gateways.dummy";
- $myname = "gateways-config.cgi";
- $title = "Gateway Configuration";
-
- $js_main =
- "type = \"address\";
- $js_account_main
- $js_error_box
- $js_ip
- function testAdd(form) {
- if(form.destination.value == \"\") {
- errorBox (form.destination, \"To add a new gateway, first enter \\na \"
- + \"destination IP address.\");
- return (false);
- }
- if (!testIPaddress(form.destination.value, false)) {
- errorBox (form.destination, \"The destination address \" +
- form.destination.value + \"\\nis invalid.\");
- return (false);
- }
- return (true);
- }";
-
- $js_add =
- "$js_standard
- $js_error_box
- $js_ip
- function checkForm(form) {
- if (form.route.value == \"\") {
- errorBox(form.route, \"Route interface required.\");
- }
- if (!testIPaddress(form.route.value, false)) {
- errorBox(form.route, \"Invalid route interface address.\");
- return (false);
- }
- if (!testInt(form.metric)) return (false);
- return (true);
- }
- function testInt(Ctrl) {
- if (Ctrl.value == \"\") {
- errorBox (Ctrl, \"The number of hops is required.\");
- return (false);
- }
- start = 0;
- while (Ctrl.value.charAt(start) == ' ') { start++; }
- end = Ctrl.value.length-1;
- while (Ctrl.value.charAt(end) == ' ') { end--; }
- for (n = start; n <= end; n++) {
- digit = Ctrl.value.charAt(n);
- if(! checkInt_c(digit, 10)) {
- errorBox (Ctrl, \"The number of hops must be \\na valid integer.\");
- return (false);
- }
- }
- str = Ctrl.value.substring(start,end+1); num = parseInt(str);
- if (num > 16) {
- errorBox (Ctrl, \"The number of hops must be \\nless than 16.\");
- return (false);
- }
- return (true);
- }";
-
- $js_edit =
- "$js_standard
- $js_error_box
- $js_ip
- function checkForm(form) {
- if (form.route.value == \"\") {
- errorBox(form.route, \"Route interface required.\");
- }
- if (!testIPaddress(form.route.value, false)) {
- errorBox(form.route, \"Invalid route interface address.\");
- return (false);
- }
- if (!testInt(form.metric)) return (false);
- return (true);
- }
- function testInt(Ctrl) {
- if (Ctrl.value == \"\") {
- errorBox (Ctrl, \"The number of hops is required.\");
- return (false);
- }
- start = 0;
- while (Ctrl.value.charAt(start) == ' ') { start++; }
- end = Ctrl.value.length-1;
- while (Ctrl.value.charAt(end) == ' ') { end--; }
- for (n = start; n <= end; n++) {
- digit = Ctrl.value.charAt(n);
- if(! checkInt_c(digit, 10)) {
- errorBox (Ctrl, \"The number of hops must be \\na valid integer.\");
- return (false);
- }
- }
- str = Ctrl.value.substring(start,end+1); num = parseInt(str);
- if (num > 16) {
- errorBox (Ctrl, \"The number of hops must be \\nless than 16.\");
- return (false);
- }
- return (true);
- }";
-
-
- print "Content-type: text/html\n\n";
-
- &get_fields;
- &getGateways;
-
- $delete = 0;
-
- if (%fld) {
- $help = $document_root . $ENV{"SCRIPT_NAME"};
- $help =~ s/cgi$/hlp/;
- exec $help if ($fld{'help'} eq "Help");
-
- $fld{'chosen'} =~ /([\w.]+)/;
- $fld{'chosen'} = $1;
- if ($fld{"add"}) {
- &validAdd;
- $val{'metric'} = 1;
- &getAdd;
- exit 0;
- }
- elsif ($fld{"doAdd"}) {
- &valid(0);
- &doAdd;
- $fld{'destination'} = "";
- &getGateways;
- &routed_hup;
- }
- elsif ($fld{"doEdit"}) {
- &valid(1);
- &doEdit;
- &getGateways;
- &routed_hup;
- }
- elsif ($fld{"edit"}) {
- &error(2,"To edit an existing gateway, first choose one from the list,
- then click the edit button.") if !$fld{'chosen'};
- &getGateways($fld{'chosen'});
- &putEdit;
- &getEdit;
- exit 0;
- }
- elsif ($fld{"delete"}) {
- &error(2,"To delete an existing gateway, first choose one from the
- list, then click the delete button.") if !$fld{'chosen'};
- $delete = 1;
- $message = qq|Click "Ok" to save changes.|;
- }
- elsif ($fld{"doit"}) {
- if ($erd ne $fld{'erd'}) { &changeStatus; }
- if ($fld{'delGateway'}) { &doDelete; };
- &getGateways;
- &routed_hup;
- }
- else {
- $message = "Use buttons to submit form.";
- }
-
- if (!$message) { $message = "No change made."; }
- %val = %fld;
- }
-
- &generic;
-
- sub routed_hup {
- system("/sbin/killall", "routed");
-
- open(IN,"< /etc/config/routed.options");
- while(<IN>) {
- chop($_);
- $configFile .= " $_";
- }
- close(IN);
-
- system("/usr/etc/routed $configFile > /dev/null 2>&1");
- }
-
- sub valid {
- &error($_[0],"Invalid route address.") if !$fld{'route'} || &check_ipaddr($fld{'route'});
- &error($_[0],"Number of hops must be an integer.") if $fld{'metric'} =~ /[^0-9-]/;
- &error($_[0],"Number of hops must be greater than zero.") if $fld{'metric'} < 1;
- &error($_[0],"Number of hops must be no greater than 16.") if $fld{'metric'} > 16;
- }
-
- sub validAdd {
- &error(2,"You must provide a gateway address.") if !$fld{'destination'};
- &error(2,"Invalid gateway address.") if &check_ipaddr($fld{'destination'});
- }
-
- sub error {
- &error_block($_[1]);
- %val = %fld;
- if ($_[0] == 0) { &getAdd; }
- elsif ($_[0] == 1) { &getEdit; }
- else { &generic; }
- exit 0;
- }
-
- sub changeStatus {
- if ($fld{'erd'} eq 'Yes') {
- system("/etc/chkconfig", "routed", "on");
- system("/etc/killall", "routed");
- open(IN,"< /etc/config/routed.options");
- while(<IN>) {
- chop($_);
- $configFile .= " $_";
- }
- close(IN);
- system("/usr/etc/routed $configFile > /dev/null 2>&1");
- $message = "Dynamic routing enabled.";
- }
- else {
- system("/etc/chkconfig", "routed", "off");
- system("/etc/killall", "routed");
- $message = "Dynamic routing disabled.";
- }
- }
-
- sub doDelete {
- open(IN,"< $conf");
- open(OUT,"> $dummy");
- while(<IN>) {
- @items = split(/\s+/);
- if ($items[1] eq $fld{'delGateway'}) { print OUT "# $_"; }
- else { print OUT $_; }
- }
- close(IN);
- close(OUT);
- rename($dummy,$conf);
-
- $message = "Gateway deleted.";
- }
-
- sub doAdd {
- open(OUT,">> $conf");
- print OUT "$fld{'type'} $fld{'destination'} gateway $fld{'route'} ";
- print OUT "metric $fld{'metric'} $fld{'mode'}\n";
- close(OUT);
-
- $message = "Gateway added.";
- }
-
- sub putEdit {
- $val{'type'} = $type;
- $val{'mode'} = $mode;
- $val{'route'} = $rout;
- $val{'metric'} = $metr;
- }
-
- sub doEdit {
- open(IN,"< $conf");
- open(OUT,"> $dummy");
- while(<IN>) {
- @items = split(/\s+/);
- if ($items[1] eq $fld{'chosen'}) { print OUT "# $_"; }
- else { print OUT $_; }
- }
- print OUT "$fld{'type'} $fld{'chosen'} gateway $fld{'route'} ";
- print OUT "metric $fld{'metric'} $fld{'mode'}\n";
- close(IN);
- close(OUT);
- rename($dummy,$conf);
-
- $message = "Gateway edited.";
- }
-
- sub getEdit {
- &js_title_block($title,$js_edit);
- &header_block("Edit Gateway");
-
- print "<form name=StandardForm action=$myname method=post onSubmit=\"return runSubmit()\">\n";
-
- print "<input type=hidden name=chosen value=$fld{'chosen'}>";
-
- print "<center><table width=450>";
-
- print "<tr><th align=left>IP address of gateway destination:</th><td>
- <tt>$fld{'chosen'}</tt></td></tr>";
- print "<tr><th align=left>IP address of route interface:</th><td>",
- &text('route',$val{'route'},16),"</td></tr>";
- print "<tr><th align=left>Type of network gateway:</th><td>",
- &select('type',$val{'type'},'net','host'),"</td></tr>";
- print "<tr><th align=left>Mode of network gateway:</th><td>",
- &select('mode',$val{'mode'},'active','passive'),"</td></tr>";
- print "<tr><th align=left>Number of hops from route interface to
- destination:</th><td>",
- &text('metric',$val{'metric'},5),"</td></tr>";
-
- print "</table></center>";
-
- print &js_buttons('doEdit','Ok','onClick="markOK()"','onClick="markOther()"');
-
- print '</form>';
- }
-
- sub getAdd {
- &js_title_block($title,$js_add);
- &header_block("Add New Gateway");
-
- print "<form name=StandardForm action=$myname method=post onSubmit=\"return runSubmit()\">\n";
-
- print "<input type=hidden name=destination value=$fld{'destination'}>";
-
- print "<center><table width=450>";
-
- print "<tr><th align=left>IP address of gateway destination:</th><td>
- <tt>$fld{'destination'}</tt></td></tr>";
- print "<tr><th align=left>IP address of route interface:</th><td>",
- &text('route',$val{'route'},16),"</td></tr>";
- print "<tr><th align=left>Type of network gateway:</th><td>",
- &select('type',$val{'type'},'net','host'),"</td></tr>";
- print "<tr><th align=left>Mode of network gateway:</th><td>",
- &select('mode',$val{'mode'},'active','passive'),"</td></tr>";
- print "<tr><th align=left>Number of hops from route interface to
- destination:</th><td>",
- &text('metric',$val{'metric'},5),"</td></tr>";
-
- print "</table></center>";
-
- print &js_buttons('doAdd','Ok','onClick="markOK()"','onClick="markOther()"');
-
- print '</form>';
- }
-
- sub generic {
- &js_title_block($title,$js_main);
- &header_block($title);
-
- print "<i>$message</i>";
-
- print "<form name=AccountForm action=$myname method=post onSubmit=\"return runSubmit()\">\n";
-
- print "<center><table width=450>\n";
-
- print "<tr><th align=left>Enable dynamic routing:</th><th align=left>",
- &radio('erd',$erd,'Yes','No'),"</th></tr>\n";
-
- print "<tr><th align=left>";
- print qq|<input type=submit name=add value="Add New Gateway" onClick="markAdd()"></th>|;
- print "\n<td><input size=19 type=text name=destination
- value=$val{'destination'}>";
- print "</td></tr>\n";
-
- if ($delete) {
- undef @locList;
- foreach $arg (@gateways) {
- if ($arg ne $fld{'chosen'}) {
- push(@locList,$arg); }
- }
- print "<input type=hidden name=delGateway value=$fld{'chosen'}>\n";
- } else { @locList = @gateways; }
-
- print "<tr><th align=left>";
- print qq|<input type=submit name=edit value="Edit Selected Gateway" onClick="markEdit()"></th>|;
- print "\n<td rowspan=2>", &choice_list(*locList,"chosen",20), "</td></tr>\n";
-
- print "<tr><th align=left>";
- print qq|<input type=submit name=delete value="Delete Selected Gateway" onClick="markDelete()"></th></tr>|;
-
- print "\n</table></center>\n";
-
- print &js_buttons('doit','Ok','onClick="markOther()"','onClick="markOther()"');
-
- print '</form>';
- }
-
- sub getGateways {
- undef @gateways;
-
- open(GATE, "< $conf");
- while (<GATE>) {
- @items = split(/\s+/);
- if ($items[0] ne 'net' && $items[0] ne 'host') { next; }
- push(@gateways,$items[1]);
- if ($items[1] eq $_[0]) {
- $type = $items[0];
- $rout = $items[3];
- $metr = $items[5];
- $mode = $items[6];
- }
- }
- close(GATE);
-
- $erd = &get_config("routed");
- }
-